<?php

class Db_Tables_Members extends Zend_Db_Table
{
    protected $_name = 'members';
	var $member_id;
	var $head_image;
	var $gender;
	var $nick_name;
	
	function LoadMemberInfoToSession()
	{
		$result = FALSE;
		
		if($this->member_id)
		{
			$row = $this->fetchRow("member_id='".$this->member_id."'");
			
			if($row)
			{
				if(!$_SESSION['member_info'])
				{
					$_SESSION['member_info'] = array();
				}
				
				$_SESSION['member_info']['member_id'] = $row->member_id;
				$_SESSION['member_info']['nick_name'] = $row->nick_name;
				$_SESSION['member_info']['cellphone'] = $row->cellphone;
				
				$result = TRUE;
			}
		}
		
		return $result;
	}
	
	function ExitMemberFromSession()
	{
		unset($_SESSION['member_info']['member_id']);
		unset($_SESSION['member_info']['nick_name']);
		
		return TRUE;
	}
	
	function UpdateWechatInfo()
	{
		$result = FALSE;
		
		if($this->member_id)
		{
			$row = $this->fetchRow("member_id=".$this->member_id);
			
			if($row)
			{
				$row->head_image = $this->head_image;
				
				if(!$row->nick_name)
				{
					$row->nick_name = $this->nick_name;
				}
				
				if(!$row->gender)
				{
					$row->gender = $this->gender;
				}
				
				if($row->save())
				{
					$result = TRUE;
				}
			}
		}
		
		return $result;
	}
}